package condominio.servlet.usuario;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import condominio.excepcion.DAOExcepcion;
import condominio.modelo.Persona;
import condominio.negocio.condominioNegocio;

/**
 * Servlet implementation class RegistraUsuarioServlet
 */
@WebServlet("/RegistraUsuarioServlet")
public class RegistraUsuarioServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegistraUsuarioServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String a = request.getParameter("nombres");
		String b = request.getParameter("apellidos");
		String c = request.getParameter("dni");
		String d = request.getParameter("fecha");
		String e1 = request.getParameter("correo");
		String f = request.getParameter("clave");
		String g = request.getParameter("estado");
		String h = request.getParameter("tipo");
		

		Persona pe = new Persona();
		pe.setTipo(h);
		pe.setNombres(a);
		pe.setApellidos(b);
		pe.setDni(c);
		pe.setFechaNacimiento(d);
		pe.setMail(e1);
		pe.setContrasena(f);
		pe.setEstado(g);
	
		condominioNegocio negocio = new condominioNegocio();
		try {
			negocio.insertarPersona(pe);
			response.sendRedirect(request.getContextPath() + "/RegistraUsuarioServlet");
		
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
	
	}
	
	

}
